[Fix] Reject non-divisible GQA head counts - #1032
Open
morluto wants to merge 1 commit into
Open
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This was referenced Aug 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Several attention paths derived the GQA group size using
HQ // Hwithout first requiring divisibility. A nonzero remainder can leave query heads uncovered or map a query head beyond the available KV heads.Add a shared group-size validator and use it across attention, decoding, NSA, Parallax, DSA, and forgetting-attention reference paths. NSA retains its additional power-of-two and minimum group-size requirements.
Valid divisible layouts are unchanged. Invalid layouts now raise
ValueErrorbefore repetition or kernel launch.Fixes #1029.
Failure modes
Integer division gives
HQ = H * G + r, whereG = HQ // Handr = HQ % H. Equal GQA groups cover exactlyH * Gquery heads, so anyr > 0necessarily leaves a remainder outside that mapping.NSA demonstrates the uncovered-head case:
The old NSA guard accepted
G=16because it is a power of two and at least 16.Query-head-indexed kernels can instead produce an invalid KV index:
The shared helper rejects
H == 0andHQ % H != 0before either mapping can occur.Scope
The same invariant is applied to optimized and reference paths so test/reference behavior matches public entrypoints. No kernel math or valid dispatch behavior changes.
Suggested review order
fla/ops/utils/head.pyTest plan
python3 -m compileall -q fla/ops/attn fla/ops/nsa fla/ops/parallax fla/ops/dsa/naive.py fla/ops/forgetting_attn/naive.py fla/ops/utils/head.pyruff check fla/ops/attn fla/ops/nsa fla/ops/parallax fla/ops/dsa/naive.py fla/ops/forgetting_attn/naive.py fla/ops/utils/head.pyCompatibility
This changes only previously invalid GQA layouts. Valid callers are unaffected.